﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using Core.Library;

namespace Event
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError().GetBaseException();
            //var writeErrorToFile = ConfigurationManager.AppSettings["WriteErrorToFile"];
            var writeErrorToFile = "1";
            if (writeErrorToFile != null && writeErrorToFile.ToUpper() == "1")
            {
                var err = new CreateLogFiles();
                err.ErrorLog(Server.MapPath("/ErrorLog"), Request.Url + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
                try
                {
                    Logging.SendMail("spn.log@gmail.com", null, "[Event - stylist]ErrorLog - " + ConfigurationManager.AppSettings["SiteURL"] + " - " + DateTime.Now, Request.Url + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace, null);
                }
                catch (Exception)
                { }
            }
            string host = ConfigurationManager.AppSettings["SiteURL"];
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Status = "301 Moved Permanently";
            HttpContext.Current.Response.AddHeader("Location", host + "404.aspx");
            HttpContext.Current.Response.CacheControl = "no-cache";
            HttpContext.Current.Response.End();
        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {
        }
    }
}